package com.yx.changdao.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yx.changdao.common.annotation.AutoLog;
import com.yx.changdao.common.annotation.ShiroDesc;
import com.yx.changdao.common.data.Pager;
import com.yx.changdao.common.data.Result;
import com.yx.changdao.common.entity.*;
import com.yx.changdao.common.enums.Category;
import com.yx.changdao.common.enums.DifficultLevel;
import com.yx.changdao.common.enums.ScoreEnum;
import com.yx.changdao.common.enums.problem.Report;
import com.yx.changdao.common.exception.AlertException;
import com.yx.changdao.common.utils.*;
import com.yx.changdao.common.vo.BuildDetailWordExportVo;
import com.yx.changdao.common.vo.WordExportVo;
import com.yx.changdao.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.*;

/**
 * @Description: <br/>
 * 交办单办结单导出
 * <p>
 * <br/>
 * @Auther: zcz
 * @create 2020/05/11 10:20
 */
@Validated
@RestController
@RequestMapping("/word/export")
@Slf4j
public class WordExportController {

    /**
     * 问题服务
     */
    @Autowired
    private ProblemService problemService;
    /**
     * 问题服务
     */
    @Autowired
    private ProblemInfoService problemInfoService;
    /**
     * 问题服务
     */
    @Autowired
    private ProblemDealService problemDealService;
    /**
     * 户的服务
     */
    @Autowired
    private CommunityBuildDetailService communityBuildDetailService;
    /**
     * 户的服务
     */
    @Autowired
    private CommunityBuildService communityBuildService;
    /**
     * 工作人员服务
     */
    @Autowired
    private DepWorkerService depWorkerService;

    /**
     * 交办单列表
     *
     * @param page
     * @param limit
     * @return
     * @throws AlertException
     */
    @AutoLog
    @GetMapping("/jbd/list")
    @RequiresPermissions("word:export:list")
    @ShiroDesc("交办单/办结单:列表")
    public Result getJbds(
            @RequestParam(value = "page") Long page,
            @RequestParam(value = "limit", required = false) Integer limit) throws AlertException {
        if (limit == null) {
            limit = SysConst.LIMIT_PAGE;
        }
        Page<Problem> pager = new Page<>(page, limit);
        // 交办单 默认的是 已分配 and 办理难度确定 and 未逾期and 未评价 的子信息列表
        QueryWrapper<Problem> qw = SysUtils.autoCnd(Problem.class);

        qw.eq(Problem.DIFFICULT_LEVEL_STATUS, 2); //难度通过的
        qw.ne(Problem.IF_TIMEOUT, 1);
        qw.eq(Problem.IF_ASSESS, 0);

        Page<Problem> problemPage = this.problemService.page(pager, qw);
        problemPage.getRecords().forEach(p -> p.setIfReportName(Report.info(p.getIfReport()).n()));
        Map<String, Object> map = new HashMap<>();
        map.put("list", problemPage.getRecords());
        map.put("pager", new Pager(problemPage));

        setNums(map);

        return Result.ok().data(map);
    }

    //设置交办单和办结单数量
    private void setNums(Map<String, Object> map) {
        int jbd = problemService.count(new QueryWrapper<Problem>()
                .eq(Problem.DIFFICULT_LEVEL_STATUS, 2) //难度通过的
                .ne(Problem.IF_TIMEOUT, 1)
                .eq(Problem.IF_ASSESS, 0));

        int bjd = problemService.count(new QueryWrapper<Problem>()
                .and(wrapper -> wrapper.eq(Problem.IF_ASSESS, 1).or().eq(Problem.IF_TIMEOUT, 1)));

        map.put("jbd", jbd);
        map.put("bjd", bjd);
    }

    /**
     * 办结单列表
     *
     * @param page
     * @param limit
     * @return
     * @throws AlertException
     */
    @AutoLog
    @GetMapping("/bjd/list")
    @RequiresPermissions("word:export:list")
    @ShiroDesc("交办单/办结单:列表")
    public Result getBjds(
            @RequestParam(value = "page") Long page,
            @RequestParam(value = "limit", required = false) Integer limit) throws AlertException {
        if (limit == null) {
            limit = SysConst.LIMIT_PAGE;
        }
        Page<Problem> pager = new Page<>(page, limit);
        // 办结单 默认的是 已评价 or 已逾期 的子信息列表
        QueryWrapper<Problem> qw = SysUtils.autoCnd(Problem.class);

        qw.and(wrapper -> wrapper.eq(Problem.IF_ASSESS, 1).or().eq(Problem.IF_TIMEOUT, 1));

        Page<Problem> problemPage = this.problemService.page(pager, qw);
        problemPage.getRecords().forEach(p -> p.setIfReportName(Report.info(p.getIfReport()).n()));
        Map<String, Object> map = new HashMap<>();
        map.put("list", problemPage.getRecords());
        map.put("pager", new Pager(problemPage));

        setNums(map);

        return Result.ok().data(map);
    }

    /**
     * 交办单查询（总控 执行公用）
     *
     * @param problemId
     * @return
     * @throws AlertException
     */
    @AutoLog
    @GetMapping("/jbd")
    public Result getJbd(@RequestParam("problemId") String problemId) throws AlertException {
        Problem problem = problemService.getOne(new QueryWrapper<Problem>().eq(Problem.ID, problemId));
        WordExportVo exportVo = getWordExportVo(problem, "1");
        return Result.ok().data(exportVo);
    }

    /**
     * 办结单查询
     *
     * @param problemId
     * @return
     * @throws AlertException
     */
    @AutoLog
    @GetMapping("/bjd")
    public Result getBjd(@RequestParam("problemId") String problemId) throws AlertException {
        Problem problem = problemService.getOne(new QueryWrapper<Problem>().eq(Problem.ID, problemId));
        WordExportVo exportVo = getWordExportVo(problem, "2");
        return Result.ok().data(exportVo);
    }

    /**
     * 根据id导出事项交办单（总控 执行公用）
     *
     * @param response
     * @throws AlertException
     * @throws IOException
     */
    @AutoLog
    @GetMapping("/jbd/export")
    public void jbdExport(HttpServletResponse response, @RequestParam("problemIds") String problemIds) throws AlertException, IOException {
        // type 1交办单   2办结单
        Map<String, Object> map = getMapByProblemIds(problemIds, "1");
        export(response, "事项交办单(可多个执行)", "事项交办单", map);
    }

    /**
     * 根据id导出事项办结单
     *
     * @param response
     * @throws AlertException
     * @throws IOException
     */
    @AutoLog
    @GetMapping("/bjd/export")
    public void bjdExport(HttpServletResponse response, @RequestParam("problemIds") String problemIds) throws AlertException, IOException {
        // type 1交办单   2办结单
        Map<String, Object> map = getMapByProblemIds(problemIds, "2");
        export(response, "事项办结单(可多个)", "事项办结单", map);
    }

    /**
     * 根据查询条件导出事项交办单
     *
     * @param response
     * @throws AlertException
     * @throws IOException
     */
    @AutoLog
    @GetMapping("/jbd/search/export")
    public void jbdSearchExport(HttpServletResponse response) throws AlertException, IOException {
        // 交办单 默认的是 已分配 and 办理难度确定 and 未逾期and 未评价 的子信息列表
        QueryWrapper<Problem> qw = SysUtils.autoCnd(Problem.class);
        qw.in(Problem.DIFFICULT_LEVEL_STATUS, DifficultLevel.GENERAL.n(), DifficultLevel.HARD.n(), DifficultLevel.SIMPLE.n(), DifficultLevel.STINT.n());
        qw.ne(Problem.IF_TIMEOUT, 1);
        qw.eq(Problem.IF_ASSESS, 0);
        List<Problem> list = problemService.list(qw);
        if (!Faster.IsNotEmpty(list)) {
            throw new AlertException("未查到可导出信息");
        }
        // type 1交办单   2办结单
        Map<String, Object> map = getMapByProblems(list, "1");
        export(response, "事项交办单(可多个)", "事项交办单", map);

    }

    /**
     * 根据查询条件事项办结单
     *
     * @param response
     * @throws AlertException
     * @throws IOException
     */
    @AutoLog
    @GetMapping("/bjd/search/export")
    public void bjdSearchExport(HttpServletResponse response) throws AlertException, IOException {
        // 办结单 默认的是 已评价 or 已逾期 的子信息列表
        QueryWrapper<Problem> qw = SysUtils.autoCnd(Problem.class);
        qw.and(wrapper -> wrapper.eq(Problem.IF_ASSESS, 1).or().eq(Problem.IF_TIMEOUT, 1));
        List<Problem> list = problemService.list(qw);
        if (!Faster.IsNotEmpty(list)) {
            throw new AlertException("未查到可导出信息");
        }
        // type 1交办单   2办结单
        Map<String, Object> map = getMapByProblems(list, "1");
        export(response, "事项办结单(可多个)", "事项办结单", map);
    }

    /**
     * 封装map
     *
     * @param problems
     * @param type
     * @return
     */
    private Map<String, Object> getMapByProblems(List<Problem> problems, String type) {
        Map<String, Object> rows = new HashMap<>();
        ArrayList<WordExportVo> list = new ArrayList<>();
        for (Problem problem : problems) {
            WordExportVo wordExportVo = getWordExportVo(problem, type);
            list.add(wordExportVo);
        }
        rows.put("rows", list);
        return rows;
    }

    /**
     * 封装map
     *
     * @param problemIds
     * @param type
     * @return
     */
    private Map<String, Object> getMapByProblemIds(String problemIds, String type) throws AlertException {
        String[] split = problemIds.split(",");
        Map<String, Object> rows = new HashMap<>();
        List<WordExportVo> list = new ArrayList<>();
        for (String problemId : split) {
            Problem problem = problemService.getOne(new QueryWrapper<Problem>().eq(Problem.ID, problemId));
            if (Faster.isNotNull(problem)) {
                WordExportVo wordExportVo = getWordExportVo(problem, type);
                list.add(wordExportVo);
            }
        }
        if (!Faster.IsNotEmpty(list)) {
            throw new AlertException("未查到可导出信息");
        }
        rows.put("rows", list);
        return rows;
    }

    /**
     * 问题对象转导出对象
     *
     * @param problem 问题对象
     * @param type    1交办单   2办结单
     * @return
     */
    private WordExportVo getWordExportVo(Problem problem, String type) {
        Calendar date = Calendar.getInstance();
        WordExportVo wordExportVo = new WordExportVo();
        wordExportVo.setObjyear(date.get(Calendar.YEAR) + "");
        int month = date.get(Calendar.MONTH) + 1;
        wordExportVo.setObjmonth(month + "");
        wordExportVo.setObjday(date.get(Calendar.DAY_OF_MONTH) + "");
        wordExportVo.setObjsxbh(problem.getId() + "");
        wordExportVo.setObjtbdw(problem.getReportDepName());
        wordExportVo.setObjjmxm(problem.getResidentName());
        wordExportVo.setObjxingbie(problem.getResidentSex());
        // 地址：楼名+单元+户名
        StringBuffer jzdz = new StringBuffer();
        CommunityBuildDetail communityBuildDetail = communityBuildDetailService.getById(problem.getBuildDetailId());
        if (!Objects.isNull(communityBuildDetail)) {
            CommunityBuild build = communityBuildService.getById(communityBuildDetail.getBuildId());
            if (!Objects.isNull(build)) {
                jzdz.append(build.getBuildName());
            }
            jzdz.append(communityBuildDetail.getUnit()).append("单元").append(communityBuildDetail.getDoorPlate()).append("室");
        }
        wordExportVo.setObjjzdz(jzdz + "");
        wordExportVo.setObjlxdh(problem.getResidentPhone());
        wordExportVo.setObjsxdj(problem.getDifficultLevel() + "(" + getDay(problem.getDifficultLevel()) + "天)");
        wordExportVo.setObjqssj("");
        wordExportVo.setObjyjjynr(problem.getContent());
        wordExportVo.setObjzfgb1(problem.getContact1Name());
        wordExportVo.setObjlxdh1(problem.getContact1Phone());
        wordExportVo.setObjzfgb2(problem.getContact2Name());
        wordExportVo.setObjlxdh2(problem.getContact2Phone());

        ProblemInfo problemInfo = problemInfoService.getById(problem.getProblemInfoId());
        if (!Objects.isNull(problemInfo)) {
            wordExportVo.setObjjbyj(problemInfo.getAssignOpinion());
        }
        // wordExportVo.setObjjbyj(problem.getAssignOpinion());

        wordExportVo.setObjjbyj(problem.getAssignOpinion()); //分配意见

        wordExportVo.setObjdfr(problem.getDealUsername());
        wordExportVo.setObjdfdh(problem.getDealPhone());
        wordExportVo.setObjdfsj(DateUtils.parseDateToStr(DateUtils.DATE_TIME_PATTERN, problem.getDealTime()));
        // 自主解决类问题审批通过时间为签收时间   否则难度审批通过时间为签收时间
        if (Category.SEF.n().equals(problem.getCategory())) {
            wordExportVo.setObjqssj(DateUtils.parseDateToStr(DateUtils.DATE_TIME_PATTERN, problem.getCreateTime()));
        } else {
            wordExportVo.setObjqssj(DateUtils.parseDateToStr(DateUtils.DATE_TIME_PATTERN, problem.getCreateTime()));
        }
        // type:  1交办单   2办结单
        if ("2".equals(type)) {
            if (1 == problem.getIfTimeout()) {
                wordExportVo.setObjcljg("已逾期");
            } else {
                ProblemDeal problemDeal = problemDealService.getOne(new QueryWrapper<ProblemDeal>()
                        .eq(ProblemDeal.PROBLEM_ID, problem.getId())
                        .orderByAsc(ProblemDeal.CREATE_TIME)
                        .last("limit 0 , 1"));
                if (!Faster.isNull(problemDeal)) {
                    wordExportVo.setObjcljg(problemDeal.getDealContent());
                }
            }
            // 诉求人是否满意
            ScoreEnum scoreEnum = ScoreEnum.info(problem.getAssessResult());
            String ifmy = null == scoreEnum ? "" : scoreEnum.info();
            wordExportVo.setObjifmy(ifmy);
        }
        return wordExportVo;
    }

    /**
     * 所需办理时间
     *
     * @param difficultLevel
     * @return
     * @throws AlertException
     */
    private String getDay(String difficultLevel) {
        if (DifficultLevel.SIMPLE.n().equals(difficultLevel)) {
            return "3";
        } else if (DifficultLevel.GENERAL.n().equals(difficultLevel)
                || DifficultLevel.STINT.n().equals(difficultLevel)) {
            return "7";
        } else if (DifficultLevel.HARD.n().equals(difficultLevel)) {
            return "60";
        }
        return null;
    }


    /**
     * 导出
     *
     * @param response
     * @param fileName 模板文件名
     * @param docName  导出文件名
     * @param dataMap
     * @throws AlertException
     * @throws IOException
     */
    public void export(HttpServletResponse response, String fileName, String docName, Map<String, Object> dataMap) throws AlertException, IOException {
        URL url = ResourceUtils.getURL("classpath:public/");
        String ftlPath = url.getPath() + fileName + ".ftl";
        String docPath = url.getPath() + docName + ".doc";
        File docFile = null;
        try {
            // 创建本地临时文件
            WordExportUtil.getInstance().createDocFile(ftlPath, dataMap, docPath, 1);
            // 写出到前端
            docFile = ResourceUtils.getFile(docPath);
            Faster.download(response, docFile);
        } catch (Exception e) {
            e.getMessage();
        } finally {
            // 删除临时文件
            if (null != docFile) {
                docFile.delete();
            }
        }
    }

// ---------------------执行部门交办单--------------------------


    /**
     * 执行部门   交办单列表
     *
     * @param page
     * @param limit
     * @return
     * @throws AlertException
     */
    @AutoLog
    @GetMapping("/execute/jbd/list")
    @RequiresPermissions("execute:word:export:list")
    @ShiroDesc("执行部门交办单:列表")
    public Result getExecuteJbds(
            @RequestParam(value = "page") Long page,
            @RequestParam(value = "limit", required = false) Integer limit) throws AlertException {
        if (limit == null) {
            limit = SysConst.LIMIT_PAGE;
        }
        Page<Problem> pager = new Page<>(page, limit);
        // 交办单 默认的是 已分配 and 办理难度确定 and 未逾期and 未评价 的子信息列表
        QueryWrapper<Problem> qw = SysUtils.autoCnd(Problem.class);

        qw.eq(Problem.DIFFICULT_LEVEL_STATUS, 2); //难度通过的
        qw.ne(Problem.IF_TIMEOUT, 1);
        qw.eq(Problem.IF_ASSESS, 0);
        qw.eq(Problem.DEP_ID, SysUtils.currentUser().getDepId());

        Page<Problem> problemPage = this.problemService.page(pager, qw);
        problemPage.getRecords().forEach(p -> p.setIfReportName(Report.info(p.getIfReport()).n()));
        Map<String, Object> map = new HashMap<>();
        map.put("list", problemPage.getRecords());
        map.put("pager", new Pager(problemPage));

        setNums(map);

        return Result.ok().data(map);
    }

    /**
     * 执行部门   根据查询条件导出事项交办单
     *
     * @param response
     * @throws AlertException
     * @throws IOException
     */
    @AutoLog
    @GetMapping("/execute/jbd/search/export")
    public void executeJbdSearchExport(HttpServletResponse response) throws AlertException, IOException {
        // 交办单 默认的是 已分配 and 办理难度确定 and 未逾期and 未评价 的子信息列表  本部门下
        QueryWrapper<Problem> qw = SysUtils.autoCnd(Problem.class);
        qw.in(Problem.DIFFICULT_LEVEL_STATUS, DifficultLevel.GENERAL.n(), DifficultLevel.HARD.n(), DifficultLevel.SIMPLE.n(), DifficultLevel.STINT.n());
        qw.ne(Problem.IF_TIMEOUT, 1);
        qw.eq(Problem.IF_ASSESS, 0);
        qw.eq(Problem.DEP_ID, SysUtils.currentUser().getDepId());

        List<Problem> list = problemService.list(qw);
        if (!Faster.IsNotEmpty(list)) {
            throw new AlertException("未查到可导出信息");
        }
        // type 1交办单   2办结单
        Map<String, Object> map = getMapByProblems(list, "1");
        export(response, "事项交办单(可多个)", "事项交办单", map);

    }


    // ---------------------意见分配导出交办单--------------------------

    /**
     * 根据id导出事项交办单（意见分配导出交办单，problem_info表）
     *
     * @param response
     * @throws AlertException
     * @throws IOException
     */
    @AutoLog
    @GetMapping("/assign/jbd/export")
    public void assignJbdExport(HttpServletResponse response,
                                @RequestParam("problemInfoIds") String problemInfoIds) throws AlertException, IOException {
        // 检查拟办意见
        checkAssignOpinion(problemInfoIds);
        // type 1交办单   2办结单
        Map<String, Object> map = getMapByProblemInfoIds(problemInfoIds);
        export(response, "事项交办单(可多个执行)", "事项交办单", map);
    }


    public void checkAssignOpinion(String problemInfoIds) throws AlertException {
        String[] split = problemInfoIds.split(",");
        List<String> list = Arrays.asList(split);
        List<ProblemInfo> problemInfos = problemInfoService.listByIds(list);
        if (null != problemInfoIds) {
            boolean b = problemInfos.stream().allMatch(p -> StringUtils.isNotBlank(p.getAssignOpinion()));
            if (!b) {
                throw new AlertException("请先保存拟办意见");
            }
        }
    }

    //************************************一户一档案导出word文档**********************
    /**
     * 根据id导出户的档案
     *
     * @param response
     * @throws AlertException
     * @throws IOException
     */
    @AutoLog
    @GetMapping("/buildDetail/export")
    public void buildDetailExport(HttpServletResponse response, @RequestParam("buildDetailIds") String buildDetailIds) throws AlertException, IOException {
        // type 1交办单   2办结单
//        Map<String, Object> map = getMapByProblemInfoIds(buildDetailIds);
        Map<String,Object> map = new HashMap<>();
        List<BuildDetailWordExportVo> wordExportVos = new ArrayList<>();
        BuildDetailWordExportVo wordExportVo = new BuildDetailWordExportVo();
        wordExportVo.setObjyear("s");
        wordExportVos.add(wordExportVo);
        map.put("rows",wordExportVos);
        Map<String, Object> map = getMapByProblemInfoIds(buildDetailIds);

        export(response, "家庭档案信息表", "家庭档案信息表", map);
    }

    /**
     * 更新交办意见
     *
     * @param problemInfoId
     * @param assignOpinion
     */
    public void modifyAssignOpinion(String problemInfoId, String assignOpinion) throws AlertException {
        if (StringUtils.isBlank(assignOpinion)) {
            throw new AlertException("交办意见不能为空");
        }
        UpdateWrapper<ProblemInfo> updateWrapper = new UpdateWrapper<ProblemInfo>()
                .set(ProblemInfo.ASSIGN_OPINION, assignOpinion)
                .eq(ProblemInfo.PROBLEM_INFO_ID, problemInfoId);
        problemInfoService.update(updateWrapper);
    }

    /**
     * 著问题封装map
     *
     * @param problemInfoIds
     * @return
     */
    private Map<String, Object> getMapByProblemInfoIds(String problemInfoIds) throws AlertException {
        String[] split = problemInfoIds.split(",");
        Map<String, Object> rows = new HashMap<>();
        List<WordExportVo> list = new ArrayList<>();
        for (String problemInfoId : split) {
            ProblemInfo problemInfo = problemInfoService.getOne(new QueryWrapper<ProblemInfo>().eq(ProblemInfo.PROBLEM_INFO_ID, problemInfoId));
            if (Faster.isNotNull(problemInfo)) {
                WordExportVo wordExportVo = getWordExportVo(problemInfo);
                list.add(wordExportVo);
            }
        }
        if (!Faster.IsNotEmpty(list)) {
            throw new AlertException("未查到可导出信息");
        }
        rows.put("rows", list);
        return rows;
    }

    /**
     * 主问题对象转导出对象
     *
     * @param problemInfo 问题对象
     * @return
     */
    private WordExportVo getWordExportVo(ProblemInfo problemInfo) {
        Calendar date = Calendar.getInstance();
        WordExportVo wordExportVo = new WordExportVo();
        wordExportVo.setObjyear(date.get(Calendar.YEAR) + "");
        int month = date.get(Calendar.MONTH) + 1;
        wordExportVo.setObjmonth(month + "");
        wordExportVo.setObjday(date.get(Calendar.DAY_OF_MONTH) + "");
        wordExportVo.setObjsxbh(problemInfo.getProblemInfoId() + "");
        wordExportVo.setObjtbdw(problemInfo.getReportDepName());
        wordExportVo.setObjjmxm(problemInfo.getResidentName());
        wordExportVo.setObjxingbie(problemInfo.getResidentSex());


        // 地址：楼名+单元+户名
        StringBuffer jzdz = new StringBuffer();
        CommunityBuildDetail communityBuildDetail = communityBuildDetailService.getById(problemInfo.getBuildDetailId());
        if (!Objects.isNull(communityBuildDetail)) {
            CommunityBuild build = communityBuildService.getById(communityBuildDetail.getBuildId());
            if (!Objects.isNull(build)) {
                jzdz.append(build.getBuildName());
            }
            jzdz.append(communityBuildDetail.getUnit()).append("单元").append(communityBuildDetail.getDoorPlate()).append("室");
        }
        wordExportVo.setObjjzdz(jzdz + "");
        wordExportVo.setObjlxdh(problemInfo.getResidentPhone());
        wordExportVo.setObjsxdj("");

        wordExportVo.setObjyjjynr(problemInfo.getContent());

        //查询部门的工作人员
        List<DepWorker> depWorkerList = depWorkerService.list(new QueryWrapper<DepWorker>().eq(DepWorker.CONTACT_GROUP_ID, problemInfo.getContactGroupId()));
        if (depWorkerList.size() == 0) {
            wordExportVo.setObjzfgb1("");
            wordExportVo.setObjlxdh1("");
            wordExportVo.setObjzfgb2("");
            wordExportVo.setObjlxdh2("");
        }
        if (depWorkerList.size() == 1) {
            wordExportVo.setObjzfgb1(depWorkerList.get(0).getWorkerName());
            wordExportVo.setObjlxdh1(depWorkerList.get(0).getWorkerPhone());
            wordExportVo.setObjzfgb2("");
            wordExportVo.setObjlxdh2("");
        }
        if (depWorkerList.size() == 2) {
            wordExportVo.setObjzfgb1(depWorkerList.get(0).getWorkerName());
            wordExportVo.setObjlxdh1(depWorkerList.get(0).getWorkerPhone());
            wordExportVo.setObjzfgb2(depWorkerList.get(1).getWorkerName());
            wordExportVo.setObjlxdh2(depWorkerList.get(1).getWorkerPhone());
        }

        wordExportVo.setObjjzdz(jzdz + "");
        wordExportVo.setObjlxdh(problemInfo.getResidentPhone());
        wordExportVo.setObjsxdj("");

        wordExportVo.setObjyjjynr(problemInfo.getContent());

        wordExportVo.setObjjbyj(problemInfo.getAssignOpinion());
        wordExportVo.setObjdfr("");
        wordExportVo.setObjdfdh("");

        wordExportVo.setObjcljg("");
        wordExportVo.setObjcljg("");
        wordExportVo.setObjifmy("");


        wordExportVo.setObjqssj(DateUtils.parseDateToStr(DateUtils.DATE_TIME_PATTERN,problemInfo.getReportTime()));

        return wordExportVo;
    }


    /**
     * 一户一档案封装map
     *
     * @param buildDetails
     * @return
     */
    private Map<String, Object> getMapByBuildDetails(String buildDetails) throws AlertException {
        String[] split = buildDetails.split(",");
        Map<String, Object> rows = new HashMap<>();
        List<BuildDetailWordExportVo> list = new ArrayList<>();
        for (String buildDetailId : split) {
            CommunityBuildDetail buildDetail = communityBuildDetailService.getOne(new QueryWrapper<CommunityBuildDetail>().eq(CommunityBuildDetail.ID, buildDetailId));
            if (Faster.isNotNull(buildDetail)) {
                BuildDetailWordExportVo wordExportVo = getBuildWordExportVo(buildDetail);
                list.add(wordExportVo);
            }
        }
        if (!Faster.IsNotEmpty(list)) {
            throw new AlertException("未查到可导出信息");
        }
        rows.put("rows", list);
        return rows;
    }

    /**
     * 类型转换一户一档案
     * @param communityBuildDetail
     * @return
     */
    private BuildDetailWordExportVo getBuildWordExportVo(CommunityBuildDetail communityBuildDetail) {

        BuildDetailWordExportVo wordExportVo = new BuildDetailWordExportVo();




        return wordExportVo;
    }
}
